1. yum安装
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
以下全部引用自:
Redhat7中yum安装以及问题解决办法(YUM和wget都无法使用的情况下)
解决:
1. 检查系统环境
1 | cat /etc/redhat-release |
2. 检查yum包安装情况
1 | rpm -qa |grep yum |
3. 绝对不能先删除系统自带的yum包
4. 先安装wget
yum安装不上就只能手动下载传上去了
5. 删除系统自带的yum包
1 | rpm -qa|grep yum|xargs rpm -e --nodeps(不检查依赖,直接删除rpm包) |
6. 下载yum安装包
下载地址:Index of /centos/7/os/x86_64/Packages/
1 | wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm |
7. 安装yum包
无视冲突强行安装
1 | --force 即使覆盖属于其它包的文件也强迫安装 |
8. 配置163源
1 | yum-config-manager --add-repo="http://mirrors.163.com/.help/CentOS6-Base-163.repo" |
Linux vi全局替换方法1
2
3
4
5cd /etc/yum.repos.d/
更改文件中的“$releasever”为“7”,“RPM-GPG-KEY-CentOS-6”为“RPM-GPG-KEY-CentOS-7”
:%s/$releasever/7/ge
:%s/RPM-GPG-KEY-CentOS-6/RPM-GPG-KEY-CentOS-7/ge
更改后文件示例1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52#CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-7 - Base - 163.com
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-7 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/7/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-7 - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/7/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
9. 清除缓存
1 | clean all #清理yum缓存,使设置生效 |
2. Docker CE 安装
以下全部引用自:
Centos7 安装 Docker-CE 社区版
1. 安装依赖
1 | yum install -y yum-utils device-mapper-persistent-data lvm2 |
2. 配置镜像库
1 | > yum-config-manager \ |
也可改为国内镜像
1 | yum-config-manager \ |
若要禁止edge版本
1 | yum-config-manager --disable docker-ce-edge |
3. 删除老版本docker
1 | > yum list docker |
1 | > yum list installed | grep docker |
4. 安装docker
1 | > sudo yum makecache fast |
如果生产系统需要稳定版本, 需要yum list
进行查询. 但yum list
只会显示二进制包, 加上.x86_64
会显示包含源码包的全部的包。sort -r
会按版本倒序排序.
1 | > yum list docker-ce.x86_64 --showduplicates |sort -r |
第二列是版本号. el7表示centos7. 第三列是库名.
安装指定版本: sudo yum install docker-ce-
1 | > sudo yum install docker-ce-17.03.1.ce-1.el7.centos |
5. 如果要删除
删除 docker-ce 版和镜像1
2> sudo yum remove docker-ce
> sudo rm -rf /var/lib/docker
6. 启动Docker
1 | > sudo systemctl start docker |
7. 非root用户使用docker
将需要使用 docker 的用户加入 docker 用户组
建立 docker 组:1
$ sudo groupadd docker
将当前用户加入 docker 组:1
$ sudo usermod -aG docker $USER
8. docker自启动与禁止
1 | sudo systemctl enable docker |
禁止自启动1
sudo systemctl disable docker
3. node.js安装
1. 通过包管理器安装
NodeSource Node.js Binary Distributions
Run as root on RHEL, CentOS or Fedora:
1 | curl --silent --location https://rpm.nodesource.com/setup | bash - |
Then install, as root:1
yum -y install nodejs
Optional: install build tools
To compile and install native addons from npm you may also need to install build tools:1
2yum install gcc-c++ make
# or: yum groupinstall 'Development Tools'
1 | sudo yum install nodejs npm |
2. 使用 nvm 安装
1. 安装 nvm
How to Install NVM (Node Version Manager) for Node.js on CentOS 7
1 | wget -qO- https://raw.githubusercontent.com/cnpm/nvm/master/install.sh | bash |
重启 shell ,输入 nvm --version
可以查看当前 nvm 的版本
2. 安装nodejs
nvm使用1
nvm help
查看可安装版本
1 | nvm ls-remote |
安装1
2
3nvm install v4.6.0
node --version
查看当前已经安装的版本
1 | nvm ls |
切换版本1
nvm use v4.6.0
设置默认版本1
nvm alias default v4.6.0
4. linux删除工具
trash-cli - Command Line Interface to FreeDesktop.org Trash
防止误删文件
1. 安装
1 | easy_install trash-cli |
1 | From sources |
1 | Installed /usr/lib/python2.7/site-packages/trash_cli-0.17.1.14_r0-py2.7.egg |
2. 替代 rm命令
Make “rm” Command To Move The Files To “Trash Can” Instead Of Removing Them Completely
1 | //Create a alias on .bashrc file. |
3. 命令
1 | trash-put xxx 将文件或目录移入回收站 |
5. ssh链接服务器
Connecting to a RedHat server with SSH
1 | ssh -i "xxx.pem证书文件" 服务器地址 |
ssh: The authenticity of host ‘hostname’ can’t be established
使用ssh连接远程主机时加上-o StrictHostKeyChecking=no
的选项,去掉对主机的验证检查
6. ssh链接github
以下引用自:
Centos 7 使用git 用 ssh 连接github服务器
生成ssh密钥1
ssh-keygen -t rsa -C "邮箱地址"
1 | cat id_rsa.pub |
复制内容到github的SSH and GPG keys
里
测试能否链接1
ssh -T git@github.com
ls
后看到新增的known_hosts
文件
7. Linux后台命令 nohup
nohup不挂起( no hang up)1
nohup command &
nohup成功后还需要按终端上键盘任意键退回到shell输入命令窗口,然后通过在shell中输入exit来退出终端。
jobs
查看在后台运行的命令,jobs -l
查看pid。
8. 查询端口号占用并清除
1 | lsof -i:80 |
1 | kill pid |